package com.gl.glcourses.model
{
	import com.gl.glcourses.events.GLCoursesEvent;
	import com.gl.glcourses.model.constants.Constants;
	import com.gl.glcourses.view.LoginPanel;
	import com.gl.glcourses.vos.Usuario;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	
	public class LoginPanelModel extends PresentationModel
	{				
		[Bindable]
		public var locales:ArrayCollection;
		
		[Bindable]
		public var index:int = 1;
		
		[Bindable]
		public var usuariosRecordados:ArrayCollection;

		[Bindable]
		public var usuario:String;	
		
		[Bindable]
		public var contrasenia:String;
		
		[Bindable]
		public var recordarUsuario:Boolean=true;
		
		[Bindable]
		public var cmdEnable:Boolean=true;
		
		public function login():void
		{
			if( validar() )
			{
				var event:GLCoursesEvent = new GLCoursesEvent( GLCoursesEvent.INICIAR_SESION );
				
				event.nombreLogin = usuario;
				event.contraseniaLogin = contrasenia;
				event.recordarUsuario = recordarUsuario;
				CursorManager.setBusyCursor();
				this.changeLoginButton(false);
				dispatch( event );
			}
		}

		public function validar():Boolean
		{ 
			if(usuario=="" || contrasenia=="" || contrasenia==null){
				Alert.show( Constants.getString( "other.completefields" ) ); 
				return false;
			}
			return true;
		}
		
		public function changeLoginButton(enabled:Boolean):void
		{
			this.cmdEnable = enabled;
		}
		
		
	}	
	
}